package com.zer0.tga.input;

import java.util.*;

public class Keys {
    public final class SingleKey {
        public boolean nextState = false;
        public boolean wasDown = false;
        public boolean isDown = false;

        public SingleKey() {
        	keysList.add(this);
        }

        public void tick() {
            wasDown = isDown;
            isDown = nextState;
        }

        public boolean wasPressed() {
            return !wasDown && isDown;
        }

        public boolean wasReleased() {
            return wasDown && !isDown;
        }

        public void release() {
            nextState = false;
        }
    }

    private List<SingleKey> keysList = new ArrayList<SingleKey>();

    public SingleKey up 	= 	new SingleKey();
    public SingleKey down 	= 	new SingleKey();
    public SingleKey left 	= 	new SingleKey();
	public SingleKey right 	= 	new SingleKey();
    public SingleKey fire 	= 	new SingleKey();
    public SingleKey bomb 	= 	new SingleKey();
    
    public SingleKey map_up 	= 	new SingleKey();
    public SingleKey map_down 	= 	new SingleKey();
    public SingleKey map_right 	= 	new SingleKey();
    public SingleKey map_left 	= 	new SingleKey();
    
    public SingleKey pause = new SingleKey();
    
   // public SingleKey build 	= 	new SingleKey();
   // public SingleKey use 	= 	new SingleKey();

    public void tick() {
        for (SingleKey key : keysList)
            key.tick();
    }

    public void release() {
        for (SingleKey key : keysList)
            key.release();
    }

    public List<SingleKey> getAll() {
        return keysList;
    }
}
